
#include <iostream>
#include <string.h>

using namespace std;

class stack
{
public:
    stack(int size = 2014); //构造器函数
    ~stack(); //析构函数
    void init();
    bool isempty();
    bool isfull();
    void push(int data);
    int  pop();
    void prinf();

private:
    int *space;
    int top;
    int num;
};

//构造器函数，不能返回，用于初始化
stack::stack(int size)
{
    space = new int(size);
    top = 0;
    num = size;
}

stack::~stack()
{
    delete []space;
}

#if 0
void stack::init()
{
    memset(space, 0, sizeof(space));
    top = 0;
}
#endif

bool stack::isempty()
{
    return top == 0;
}

bool stack::isfull()
{
    return top == num;
}

void stack::push(int data)
{
    space[top++] = data;
}

int stack::pop()
{
    return space[--top];
}

void stack::prinf()
{
    int i, num = top;

    cout<<"top = "<<top<<endl;
    for(i=0; i<num; ++i)
    {
        cout<<"the data["<<i<<"]="<<space[i]<<endl;
    }
}

int main(void)
{
    //stack st;
    int i = 0;

    stack st(4);

    //st.init();
    if(!st.isfull())
        st.push(32);
    if(!st.isfull())
        st.push(33);
    if(!st.isfull())
        st.push(34);
    if(!st.isfull())
        st.push(35);
    if(!st.isfull())
        st.push(36);
    st.prinf();

    while(!st.isempty())
    {
        st.pop();
    }
    st.prinf();

    return 0;
}

